<template>
  <div class="login">
    <div class="login-box">
      <div class="mid">
        <img class="bg" src="https://oss.tffire.net/file/20231112213111429.png" />
        <div class="input-box">
          <el-form :model="dataForm"
                   :rules="dataRule"
                   style="width: 100%"
                   ref="dataForm"
                   @keyup.enter.native="dataFormSubmit()"
                   status-icon>
            <el-row :gutter="10">
              <el-col :span="7">
                <el-form-item prop="userName">
                  <el-input class="info"
                            v-model="dataForm.userName"
                            placeholder="帐号"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item prop="password">
                  <el-input class="info"
                            v-model="dataForm.password"
                            type="password"
                            placeholder="密码"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-form-item prop="captcha">
                  <el-row :gutter="10">
                    <el-col :span="14">
                      <el-input v-model="dataForm.captcha"
                                placeholder="验证码">
                      </el-input>
                    </el-col>
                    <el-col :span="10"
                            class="login-captcha">
                      <img :src="captchaPath"
                           class="verification"
                           @click="getCaptcha()"
                           alt="">
                    </el-col>
                  </el-row>
                </el-form-item>
                <el-form-item>
                  <div class="item-btn"><input type="button"
                                               value="登录"
                                               @click="dataFormSubmit()"></div>
                </el-form-item>
              </el-col>
            </el-row>
            <div class="tip">
              <div>Tongfang Intelligent Fire Cloud Platform.</div>
              <div>www.tffire.net   |   400 0512 129</div>
            </div>
          </el-form>
        </div>
      </div>
<!--      <div class="title-box">-->
<!--        <div>Tongfang Intelligent Fire Cloud Platform.</div>-->
<!--        <div>www.tffire.net   |   400 0512 129</div>-->
<!--      </div>-->
    </div>
<!--    <div class="bottom copyright">Copyright © 2019-2023 江苏桐方消防科技集团股份有限公司</div>-->
  </div>
</template>

<script>
import { getUUID } from '@/utils'
export default {
  data () {
    return {
      dataForm: {
        userName: '',
        password: '',
        uuid: '',
        captcha: ''
      },
      dataRule: {
        userName: [
          { required: true, message: '帐号不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ],
        captcha: [
          { required: true, message: '验证码不能为空', trigger: 'blur' }
        ]
      },
      captchaPath: ''
    }
  },
  created () {
    this.getCaptcha()
  },
  methods: {
    // 提交表单
    dataFormSubmit () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl('/login?grant_type=admin'),
            method: 'post',
            data: this.$http.adornData({
              'principal': this.dataForm.userName,
              'credentials': this.dataForm.password,
              'sessionUUID': this.dataForm.uuid,
              'imageCode': this.dataForm.captcha
            })
          }).then(({ data }) => {
            console.log(data)
            this.$cookie.set('Authorization', 'bearer' + data.access_token)
            this.$cookie.set('userName',data.username)
            this.$router.replace({ name: 'moduleList' })
          }).catch(() => {
            this.getCaptcha()
          })
        }
      })
    },
    // 获取验证码
    getCaptcha () {
      this.dataForm.uuid = getUUID()
      this.captchaPath = this.$http.adornUrl(`/captcha.jpg?uuid=${this.dataForm.uuid}`)
      console.log(this.captchaPath);
    }
  }
}
</script>

<style lang="scss">
.login {
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #183854, #204661, #3A758F);
  //background: url(https://oss.tffire.net/file/20231109223058876.png) no-repeat;
  background-size: cover;
  position: fixed;
}

.login .login-box .top {
  margin-bottom: 30px;
  text-align: center;
}
.login .login-box .top .logo {
  font-size: 0;
}
.login .login-box .top .company {
  font-size: 16px;
  margin-top: 10px;
}
.login .login-box .mid {
  position: absolute;
  font-size: 14px;
  padding:30px 30px;
  border-radius: 11px;
  margin: auto 0;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  justify-content: flex-start;
  width: 1300px;
  height: 624px;
}

.bg{
  width: 100%;
  height: 100%;
}

.input-box{
  position: absolute;
  left: 50%;
  width: 550px;
  transform: translateX(-50%);
  top: 250px;
}

.title-box{
  position: relative;
  color: #9D3320;
  font-size: 14px;
  font-weight: bold;
  width: 300px;
  left: 29.5%;
  top: 23vh;
}

.login .login-box .mid .item-btn input {
  border: 0;
  width: 100%;
  height: 40px;
  background: #1f87e8;
  color: #fff;
  border-radius: 3px;
}
.login-captcha {
  height: 40px;
}
.verification{
  height: 35px;
  width: 100%
}
.login .login-box .bottom {
  position: absolute;
  bottom: 10%;
  width: 100%;
  font-size: 12px;
  text-align: center;
  color: white;
}
.copyright{
  position: absolute;
  bottom: 1vh;
  width: 100%;
  text-align: center;
  color: white;
}
.tip{
  position: relative;
  top:-60px;
  color: #9D3320;
  font-size: 12px;
  width: 50%;
  margin-left: 10px;
  div{
    line-height: 20px;
  }
}
</style>
